﻿using System;


namespace Daystate.ConfigurationManager
{
    /// <summary>
    /// Factors out configuration properties.
    /// </summary>
    public sealed class ConfigPropertyFactory
    {
        /// <summary>
        /// Creates new configuraton property basic on gives parameters.
        /// </summary>
        /// <param name="propertyType">Configuration property type.</param>
        /// <param name="key">Configuration property key.</param>
        /// <param name="value">Configuration property value.</param>
        /// <returns>Created configuration property.</returns>
        public static ConfigProperty CreateConfigProperty(SupportedTypesEnum propertyType, string key, object value)
        {
            // Check value type
            if (!SupportedTypes.TypesList.ContainsSecondValue(value.GetType()))
                throw new ArgumentException("Invalid value type!");

            // Create configuration property acording to its type
            ConfigProperty property = new ConfigProperty(key, value);

            return property;
        }
    }
}
